from collections import defaultdict

products = [["iphone", 6888], ["MacPro", 14800], ["小米6", 2499], ["Coffee", 31], ["Book", 60], ["Nike", 699]]
productdict = {}
for pro, price in products:
    productdict[pro] = price
print(productdict)
pdictnum = defaultdict(lambda: 0)
while True:
    g = input(">>>你想买什么？")
    if g == "q":
        break
    if g in productdict:
        pdictnum[g] += 1
        print("您选择了{},单价：{}".format(g, productdict[g]))
    else:
        print("对不起,没有您所要购买的货物")
print(pdictnum)
print("您购买的商品列表：")
print("商品\t数量\t单价\t总价")
sum = 0
for p, num in pdictnum.items():
    pcost = num * productdict[p]
    sum += pcost
    print("{}\t{}\t{}\t{}".format(p, num, productdict[p], pcost))
print("总价格：{}".format(sum))

# 缺失退出的提示